//make sure the time travel is possible physically, depending on the maps. Returns false if impossible
function timeTravelPossible(timeAsked)
{
	return !isTimeTravelling && (currentTime != timeAsked);
}

// Make objects and map modifications (caused by player's actions)
function itemTimeHarmony(timeAsked)
{
	// alert("itemharmony");
	for (var i=0; i< lvlObjectNames.length; i++) {
		if (lvlObjects[lvlObjectNames[i]].collected == false) {
			var newState = lvlObjects[lvlObjectNames[i]].objState - (currentTime - timeAsked);
			// alert("newState : " + newState);
			lvlObjects[lvlObjectNames[i]].makeState(newState);
			lvlObjects[lvlObjectNames[i]].objState = newState;
		}
	}
}

// timeAsked equals 'past', 'present' or 'future'
function timeTravel(timeAsked)
{
	//Check if timetravel is possible
	if(!timeTravelPossible(timeAsked)) return;
	isTimeTravelling = true;
	isChangingLevel = true;
	me.game.viewport.fadeIn("#000000", 400, function() { // onComplete :
		
		// Save position
		posX = mainPlayer.pos.x;
		posY = mainPlayer.pos.y + mainPlayer.height - 32;
		
		//Load Level
		var nameLevel = "level_" + currentLevel + "_" + timeArray[timeAsked];
		me.levelDirector.loadLevel(nameLevel);
		
		//Commit items modification
		itemTimeHarmony(timeAsked);
		currentTime = timeAsked;
		me.game.HUD.removeItem("footer");
		me.game.HUD.addItem("footer", new FooterBar(0, 0));
		me.game.viewport.fadeOut('#000000', 400, function() { // onComplete :
			isTimeTravelling = false;
			isChangingLevel = false;
		});
		
	});
}